import { defineStore } from "pinia";

export const useTaxStore = defineStore("tax", {
  state: () => ({
    taxData: [
      {
        id: 1,
        recordName: "记录01",
        companyName: "百度",
        taxDate: "2024-3-5",
        taxForm: "企业所得税",
        taxMoney: "10000",
        status: "已申报",
        remark: "",
      },
      {
        id: 2,
        recordName: "记录02",
        companyName: "腾讯",
        taxDate: "2024-8-5",
        taxForm: "企业所得税",
        taxMoney: "10000",
        status: "已申报",
        remark: "",
      },
      {
        id: 3,
        recordName: "记录03",
        companyName: "腾讯",
        taxDate: "2025-1-5",
        taxForm: "企业所得税",
        taxMoney: "10000",
        status: "未申报",
        remark: "",
      },
      {
        id: 4,
        recordName: "记录04",
        companyName: "腾讯",
        taxDate: "2025-4-5",
        taxForm: "企业所得税",
        taxMoney: "10000",
        status: "未申报",
        remark: "",
      },
      {
        id: 5,
        recordName: "记录05",
        companyName: "腾讯",
        taxDate: "2025-7-5",
        taxForm: "企业所得税",
        taxMoney: "10000",
        status: "未申报",
        remark: "",
      },
    ],
  }),
  actions: {
    setTaxData(newData: any) {
      this.taxData = newData;
    },
    updateTaxRecord(id: number, updatedRecord: any) {
      const index = this.taxData.findIndex((item) => item.id == id);
      if (index !== -1) {
        this.taxData[index] = { ...this.taxData[index], ...updatedRecord };
      } else {
        console.log("Record not found for ID:", id);
      }
    },
    addTaxRecord(newRecord: any) {
      this.taxData.push(newRecord);
    },
  },
});
